#pragma once

#include <boost/format.hpp>




namespace boostext
{
	/**
	 * format is an auxiliary class that inherits from boost::format
	 * to make formatting nearly as easy as with printf, without neglecting
	 * the type-safety from boost::format.
	 * It offers automated type conversion to std::string, because boost::str( boost::format() )
	 * is simply too long.
	 *
	 * The following code is a little synopsis about the usage of boost_ext::format.
	 * A more detailed explanation can be found at http://www.boost.org/doc/libs/1_38_0/libs/format/doc/format.html
	 * @code
	 * cout << format("%2% %1%") % 36 % 77;
	 * string s = format("%2% %1%") % 36 % 77; // Notice the implicit conversion
	 *
	 * format fmter("%2% %1%");
	 * fmter % 36; fmter % 77;
	 * cout << fmter;
	 * string s = fmter; // Notice the implicit conversion
	 * @endcode
	 */
	template
	<
		class _char,
		template <class> class _Traits = std::char_traits,
		template <class> class _Ax = std::allocator
	>
	class basic_format : public boost::basic_format<_char, _Traits<_char>, _Ax<_char> >
	{
	public:

		/// Typedef for the parent class
		typedef boost::basic_format<_char, _Traits<_char>, _Ax<_char> >   BF;

		/// Typedef for the underlying std::basic_string
		typedef std::basic_string<_char, _Traits<_char>, _Ax<_char> >     _String;

		/// Typedef for a type, describing sizes
		typedef typename _String::size_type                               size_type;

	public:

		/**
		 * Create a new format.
		 * Offers the same functionality that boost::format does.
		 */
		basic_format( const _String &fmt ) : boost::basic_format<_char,_Traits<_char>, _Ax<_char> >( fmt ) {}


		/**
		 * Feed another argument to the formatter.
		 */
		template
		<
			class _Ty
		>
		basic_format<_char,_Traits, _Ax>& operator%(const _Ty& x)
		{
			// __super::operator%...
			BF::operator%( x );
			return *this;
		}



		/**
		 * Automatically convert the format into a string.
		 */
		operator _String() const
		{
			return str();
		}
	};
	///////////////////////////////////////////////////////////////////////////////////////////////

	typedef basic_format<char>    format;
	typedef basic_format<wchar_t> wformat;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
